
#include "NormalRecessionBC.h"
#include "Function.h"
registerMooseObject("TrilobitaApp", NormalRecessionBC);
template<>
InputParameters validParams<NormalRecessionBC>()
{
  InputParameters params = validParams<NodalBC>();
  MooseEnum component("x y z");
  params.addRequiredParam<MooseEnum>("component", component, "The desired component of velocity.");
  params.addCoupledVar("nx", "x-component of the normal");
  params.addCoupledVar("ny", "y-component of the normal");
  params.addCoupledVar("nz", "z-component of the normal");
  params.addCoupledVar("variableold", "variable");
  params.addCoupledVar("recession_rate", "recession_rate");
  params.set<std::vector<VariableName> >("nx") = std::vector<VariableName>(1, "nodal_normal_x");
  params.set<std::vector<VariableName> >("ny") = std::vector<VariableName>(1, "nodal_normal_y");
  params.set<std::vector<VariableName> >("nz") = std::vector<VariableName>(1, "nodal_normal_z");
  return params;
}

NormalRecessionBC::NormalRecessionBC(const InputParameters & parameters) :
    NodalBC( parameters),
	_component(getParam<MooseEnum>("component")),
	_nx(coupledValueOld("nx")),
	_ny(coupledValueOld("ny")),
	_nz(coupledValueOld("nz")),
	_oldu(coupledValueOld("variableold")),
	_recession_rate(coupledValue("recession_rate"))
{
}

Real
NormalRecessionBC::computeQpResidual()
{
	if (_component == 0)
	{
		return _u[_qp]-_oldu[_qp]+_recession_rate[_qp]*_nx[_qp]*_dt;
	}
	else
	{
		if(_component == 1)
		{
			return _u[_qp]-_oldu[_qp]+_recession_rate[_qp]*_ny[_qp]*_dt;
		}
		else
		{
			return _u[_qp]-_oldu[_qp]+_recession_rate[_qp]*_nz[_qp]*_dt;
		}
	}
}
